// 入口文件
const Generator = require('yeoman-generator');

module.exports = class extends Generator {
  async prompting() {
    const answers = await this.prompt([
      {
        type: "input",
        name: "name",
        message: "Your project name",
        default: this.appname // Default to current folder name
      },
      {
        type: "confirm",
        name: "cool",
        message: "Would you like to enable the Cool feature?"
      }
    ]);
    // this.log("app name", answers.name);
    // this.log("cool feature", answers.cool);
    this.answers = answers;
  }

  // 钩子：生成文件时调用
  write() {
    // 在项目目录中写入文件, 参数：文件名，文件内容
    // this.fs.write(
    //   this.destinationPath('temp.txt'), 输出到项目目录下的temp.txt
    //   Math.random().toString()
    // );

    // 自动寻找templates下的文件
    const template = this.templatePath('foo.txt');
    const output = this.destinationPath('foo.txt');
    const context = {
      title: 'hello yeoman',
      success: false
    }
    this.fs.copyTpl(template, output, context);
  }
}

